package org.feiye.studyday28.case5;

import java.io.*;
import java.net.*;

public class TalkThread extends Thread {
	private Socket s;

	public TalkThread(Socket s) {
		this.s = s;
	}

	@Override
	public void run() {
		System.out.println(s + "连接上了。。。。");
		try {
			InputStream in = s.getInputStream();
			OutputStream out = s.getOutputStream();
			BufferedReader br = new BufferedReader(new InputStreamReader(in));
			PrintWriter pw = new PrintWriter(out);
			while (true) {
				String str2 = br.readLine();
				System.out.println("你说：" + str2);
				if (str2 == null || str2.length() == 0)
					break;

				String str = "你说的事情【" + str2 + "】，朕知道了";
				pw.println(str);
				pw.flush();
				if ("exit".equals(str2))
					break;
			}
		} catch (IOException e) {
			// TODO 自动生成的 catch 块
			e.printStackTrace();
		} finally {
			try {
				System.out.println(s + "退出了聊天");
				s.close();
			} catch (Exception e) {
				// TODO 自动生成的 catch 块
				e.printStackTrace();
			}
		}
	}
}
